next (n,x) = (n+1, x + inc)
             where inc  = 2*step
                   step = ceiling $ (fromIntegral n) / 4

alls x = take x (iterate next $ (1,1))
main = sum $ map snd $ alls $ 1001*2 - 1

